typedef struct GPS_SPacket
+{
+ US type;
+ uint32 n;
+ UC *data;
+} GPS_OPacket, *GPS_PPacket;
+
+typedef struct GPS_Serial_SPacket
{
UC dle;
UC type;
UC chk;
UC edle;
UC etx;
- UC bytes; /* Actual number of bytes (for sending) */
-} GPS_OPacket, *GPS_PPacket;
-
-
+} GPS_Serial_OPacket, *GPS_Serial_PPacket;
typedef struct GPS_SProduct_Data_Type
{
}
GPS_Make_Packet(&tra, LINK_ID[gps_link_type].Pid_Wpt_Data,
- data, (US) len);
+ data, len);
if(!GPS_Write_Packet(fd,tra))
return gps_errno;
GPS_PPacket rec;
int32 i;
int32 len;
- UC method;
+ US method;
if(!GPS_Device_On(port,&fd))
return gps_errno;
}
- GPS_Make_Packet(&tra, method, data,(US) len);
+ GPS_Make_Packet(&tra, method, data, len);
if(!GPS_Write_Packet(fd,tra))
return gps_errno;
GPS_PPacket rec;
int32 i;
int32 len;
- UC method;
+ US method;
if(!GPS_Device_On(port,&fd))
return gps_errno;
}
- GPS_Make_Packet(&tra, method, data,(US) len);
+ GPS_Make_Packet(&tra, method, data, len);
if(!GPS_Write_Packet(fd,tra))
return gps_errno;
}
GPS_Make_Packet(&tra, LINK_ID[gps_link_type].Pid_Trk_Data,
- data,(US) len);
+ data, len);
if(!GPS_Write_Packet(fd,tra))
return gps_errno;
GPS_PPacket rec;
int32 i;
int32 len;
- UC method;
+ US method;
if(gps_trk_transfer == -1)
return GPS_UNSUPPORTED;
}
- GPS_Make_Packet(&tra, method, data,(US) len);
+ GPS_Make_Packet(&tra, method, data, len);
if(!GPS_Write_Packet(fd,tra))
return gps_errno;
if(!GPS_Get_Ack(fd, &tra, &rec))
{
- GPS_Error("A301_Send: Track packet not acknowledgedn");
+ GPS_Error("A301_Send: Track packet not acknowledged");
return FRAMING_ERROR;
}
}
}
GPS_Make_Packet(&tra, LINK_ID[gps_link_type].Pid_Prx_Wpt_Data,
- data,(US) len);
+ data, len);
if(!GPS_Write_Packet(fd,tra))
return gps_errno;
}
GPS_Make_Packet(&tra, LINK_ID[gps_link_type].Pid_Almanac_Data,
- data,(US) len);
+ data, len);
if(!GPS_Write_Packet(fd,tra))
return gps_errno;
return MEMORY_ERROR;
GPS_Util_Put_Short(data,
- COMMAND_ID[gps_device_command].Cmnd_Transfer_Lap);
+ COMMAND_ID[gps_device_command].Cmnd_Transfer_Laps);
GPS_Make_Packet(&trapkt, LINK_ID[gps_link_type].Pid_Command_Data,
data,2);
if(!GPS_Write_Packet(fd,trapkt))
* but they really are runtime variable. Sigh.
*/
const char *
-Get_Pkt_Type(unsigned char p, unsigned short d0, const char **xinfo)
+Get_Pkt_Type(US p, US d0, const char **xinfo)
{
*xinfo = NULL;
#define LT LINK_ID[gps_link_type]
return "FLIBOO";
if (p == LT.Pid_Lap)
return "LAPDAT";
- if (p == LT.Pid_Wpt_Cat_Data)
+ if (p == LT.Pid_Wpt_Cat)
return "WPTCAT";
if (p == LT.Pid_Run)
return "RUNDAT";
Capability A1013: D1014
*/
-const char * Get_Pkt_Type(unsigned char p, unsigned short d0, const char **xinfo);
+const char * Get_Pkt_Type(US p, US d0, const char **xinfo);
#endif
** Get lap from GPS
**
** @param [r] port [const char *] serial port
-** @param [w] way [GPS_PLap **] pointer to lap array
+** @param [w] lap [GPS_PLap **] pointer to lap array
**
** @return [int32] number of lap entries
************************************************************************/
return (ops->Get_Ack)(fd, tra, rec);
}
-void GPS_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n)
+void GPS_Make_Packet(GPS_PPacket *packet, US type, UC *data, uint32 n)
{
- (ops->Make_Packet)(packet, type, data, n);
+ (*packet)->type = type;
+ memcpy((*packet)->data, data, n);
+ (*packet)->n = n;
}
typedef int32 (*gps_device_op10)(gpsdevh * fd, GPS_PPacket *tra, GPS_PPacket *rec);
typedef int32 (*gps_device_op12)(gpsdevh * fd, GPS_PPacket packet);
typedef int32 (*gps_device_op13)(gpsdevh * fd, GPS_PPacket *packet);
-typedef void (*gps_device_op14)(GPS_PPacket *packet, UC type, UC *data, int16 n);
typedef struct {
gps_device_op5 Device_On;
gps_device_op Device_Off;
gps_device_op10 Send_Ack;
gps_device_op10 Get_Ack;
gps_device_op13 Read_Packet;
- gps_device_op14 Make_Packet;
gps_device_op12 Write_Packet;
} gps_device_ops;
GPS_Serial_Send_Ack,
GPS_Serial_Get_Ack,
GPS_Serial_Packet_Read,
- GPS_Serial_Make_Packet,
GPS_Serial_Write_Packet,
};
(gps_device_op10) success_stub,
(gps_device_op10) success_stub,
gdu_read,
- GPS_Make_Packet_usb,
GPS_Write_Packet_usb
};
return NULL;
}
- ret->dle = ret->edle = DLE;
- ret->etx = ETX;
-
return ret;
}
**
** Lap constructor
**
-** @return [GPS_PLap] virgin track
+** @return [GPS_PLap] virgin lap
**********************************************************************/
GPS_PLap GPS_Lap_New(void)
**
** Lap destructor
**
-** @param [w] thys [GPS_PLap *] track to delete
+** @param [w] thys [GPS_PLap *] lap to delete
**
** @return [void]
**********************************************************************/
US Pid_FlightBook_Record;
US Pid_Lap;
- US Pid_Wpt_Cat_Data;
+ US Pid_Wpt_Cat;
US Pid_Run;
US Pid_Workout;
US Pid_Workout_Occurrence;
US Cmnd_Start_Pvt_Data;
US Cmnd_Stop_Pvt_Data;
US Cmnd_FlightBook_Transfer;
- US Cmnd_Transfer_Lap;
+ US Cmnd_Transfer_Laps;
US Cmnd_Transfer_Wpt_Cats;
US Cmnd_Transfer_Runs;
US Cmnd_Transfer_Workouts;
int32 isDLE;
UC *p;
int32 i;
- UC chk=0;
+ UC chk=0, chk_read;
const char *m1;
const char *m2;
if(!len)
{
- (*packet)->dle = u;
if(u != DLE)
{
(void) fprintf(stderr,"GPS_Packet_Read: No DLE. Data received, but probably not a garmin packet.\n");
if(u == ETX)
if(isDLE)
{
- (*packet)->edle = DLE;
- (*packet)->etx = ETX;
if(p-(*packet)->data-2 != (*packet)->n)
{
GPS_Error("GPS_Packet_Read: Bad count");
gps_errno = FRAMING_ERROR;
return 0;
}
- (*packet)->chk = *(p-2);
+ chk_read = *(p-2);
for(i=0,p=(*packet)->data;i<(*packet)->n;++i)
chk -= *p++;
chk -= (*packet)->type;
chk -= (*packet)->n;
- if(chk != (*packet)->chk)
+ if(chk != chk_read)
{
GPS_Error("CHECKSUM: Read error\n");
gps_errno = FRAMING_ERROR;
#include <ctype.h>
-/* @func GPS_Make_Packet ***********************************************
+/* @funcstatic Build_Serial_Packet *************************************
**
-** Forms a complete packet to send
-**
-** @param [w] packet [GPS_PPacket *] packet string
-** @param [r] type [UC] packet type
-** @param [r] data [UC *] data string
-** @param [r] n [int16] number of bytes in data string
+** Forms a complete packet to send on serial port
+*
+** @param [r] in [GPS_PPacket *] packet string with portable packet data
+** @param [w] out [GPS_Serial_PPacket *] packet string suitable for serial port
**
-** @return [void]
+** @return [US] number of data bytes to send
************************************************************************/
-
-void GPS_Serial_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n)
+static US
+Build_Serial_Packet(GPS_PPacket in, GPS_Serial_PPacket out)
{
UC *p;
UC *q;
int32 i;
UC chk=0;
+ US bytes=0;
-
- p = data;
- q = (*packet)->data;
+ p = in->data;
+ q = out->data;
- (*packet)->dle = DLE;
- (*packet)->edle = DLE;
- (*packet)->etx = ETX;
- (*packet)->n = (UC) n;
- (*packet)->type = type;
- (*packet)->bytes = 0;
+ out->dle = DLE;
+ out->edle = DLE;
+ out->etx = ETX;
+ out->n = in->n;
+ out->type = in->type;
- chk -= type;
+ chk -= in->type;
- if(n == DLE)
+ if(in->n == DLE)
{
- ++(*packet)->bytes;
+ ++bytes;
*q++ = DLE;
}
+ chk -= in->n;
- chk -= (UC) n;
-
- for(i=0;i<n;++i)
+ for(i = 0; i < in->n; ++i)
{
if(*p == DLE)
{
- ++(*packet)->bytes;
+ ++bytes;
*q++ = DLE;
}
chk -= *p;
*q++ = *p++;
- ++(*packet)->bytes;
+ ++bytes;
}
if(chk == DLE)
{
*q++ = DLE;
- ++(*packet)->bytes;
+ ++bytes;
}
- (*packet)->chk = chk;
+ out->chk = chk;
- return;
+ return bytes;
}
{
size_t ret;
const char *m1, *m2;
-
+ GPS_Serial_OPacket ser_pkt;
+ UC ser_pkt_data[MAX_GPS_PACKET_SIZE * sizeof(UC)];
+ US bytes;
+ if (packet->type >= 0xff || packet->n >= 0xff) {
+ GPS_Error("SEND: Unsupported packet type/size for serial protocol");
+ return 0;
+ }
+
+ ser_pkt.data = ser_pkt_data;
+ bytes = Build_Serial_Packet(packet, &ser_pkt);
+
GPS_Diag("Tx Data:");
- Diag(&packet->dle, 3);
- if((ret=GPS_Serial_Write(fd,(const void *) &packet->dle,(size_t)3)) == -1)
+ Diag(&ser_pkt.dle, 3);
+ if((ret=GPS_Serial_Write(fd,(const void *) &ser_pkt.dle,(size_t)3)) == -1)
{
perror("write");
GPS_Error("SEND: Write to GPS failed");
return 0;
}
- Diag(packet->data, packet->bytes);
- if((ret=GPS_Serial_Write(fd,(const void *)packet->data,(size_t)packet->bytes)) == -1)
+ Diag(ser_pkt.data, bytes);
+ if((ret=GPS_Serial_Write(fd,(const void *)ser_pkt.data,(size_t)bytes)) == -1)
{
perror("write");
GPS_Error("SEND: Write to GPS failed");
return 0;
}
- if(ret!=packet->bytes)
+ if(ret!=bytes)
{
GPS_Error("SEND: Incomplete write to GPS");
return 0;
}
- Diag(&packet->chk, 3);
+ Diag(&ser_pkt.chk, 3);
GPS_Diag(": ");
- DiagS(packet->data, packet->bytes);
- DiagS(&packet->chk, 3);
- m1 = Get_Pkt_Type(packet->type, packet->data[0], &m2);
+ DiagS(ser_pkt.data, bytes);
+ DiagS(&ser_pkt.chk, 3);
+ m1 = Get_Pkt_Type(ser_pkt.type, ser_pkt.data[0], &m2);
GPS_Diag("(%-8s%s)\n", m1, m2 ? m2 : "");
- if((ret=GPS_Serial_Write(fd,(const void *)&packet->chk,(size_t)3)) == -1)
+ if((ret=GPS_Serial_Write(fd,(const void *)&ser_pkt.chk,(size_t)3)) == -1)
{
perror("write");
GPS_Error("SEND: Write to GPS failed");
#define GPS_ARB_LEN 1024
-void GPS_Serial_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n);
int32 GPS_Serial_Write_Packet(gpsdevh *fd, GPS_PPacket packet);
int32 GPS_Serial_Send_Ack(gpsdevh *fd, GPS_PPacket *tra, GPS_PPacket *rec);
-void GPS_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n);
+void GPS_Make_Packet(GPS_PPacket *packet, US type, UC *data, uint32 n);
#endif
int rv;
unsigned char *buf = (unsigned char *) &ibuf->dbuf;
int orig_receive_state;
+ unsigned short pkt_id;
top:
orig_receive_state = receive_state;
switch (receive_state) {
fatal("Unknown receiver state %d\n", receive_state);
}
+ pkt_id = le_read16(&ibuf->gusb_pkt.pkt_id);
if (gps_show_bytes) {
int i;
const char *m1, *m2;
GPS_Diag("%c", isalnum(buf[i])? buf[i] : '.');
}
- m1 = Get_Pkt_Type(ibuf->gusb_pkt.pkt_id[0], pkttype, &m2);
+ m1 = Get_Pkt_Type(pkt_id, pkttype, &m2);
if ((rv == 0) && (receive_state == rs_frombulk) ) {m1= "RET2INTR";m2=NULL;};
GPS_Diag("(%-8s%s)\n", m1, m2 ? m2 : "");
}
/* Adjust internal state and retry the read */
- if ((rv > 0) && (ibuf->gusb_pkt.pkt_id[0] == GUSB_REQUEST_BULK)) {
+ if ((rv > 0) && (pkt_id == GUSB_REQUEST_BULK)) {
receive_state = rs_frombulk;
goto top;
}
if (gps_show_bytes) {
const unsigned short pkttype = le_read16(&opkt->gusb_pkt.databuf[0]);
+ const unsigned short pkt_id = le_read16(&opkt->gusb_pkt.pkt_id);
GPS_Diag("TX [%d]:", sz);
for(i=0;i<sz;i++)
for(i=0;i<sz;i++)
GPS_Diag("%c", isalnum(obuf[i])? obuf[i] : '.');
- m1 = Get_Pkt_Type(opkt->gusb_pkt.pkt_id[0], pkttype, &m2);
+ m1 = Get_Pkt_Type(pkt_id, pkttype, &m2);
GPS_Diag("(%-8s%s)\n", m1, m2 ? m2 : "");
}
*/
(*packet)->type = le_read16(&pkt.gusb_pkt.pkt_id);
payload_size = le_read32(&pkt.gusb_pkt.datasz);
- (*packet)->n = (UC) payload_size;
+ (*packet)->n = payload_size;
memcpy((*packet)->data, &pkt.gusb_pkt.databuf, payload_size);
return 1;
#include "garminusb.h"
#include "gpsusbint.h"
-void
-GPS_Make_Packet_usb(GPS_PPacket *packet, UC type, UC *data, int16 n)
-{
- /*
- * For the USB case, it's a little tacky that we just copy
- * the params into *packet, but we really don't have any manipulations
- * to do here. They're done in send_packet in order to keep the
- * contents of *packet identical for the serial and USB cases.
- */
-
- (*packet)->type = type;
- memcpy((*packet)->data, data, n);
- (*packet)->n = (UC) n;
-
- return;
-}
-
int32
GPS_Write_Packet_usb(gpsdevh *dh, GPS_PPacket packet)
{